package com.github.thinwonton.spring.schema;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;

public class UserBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
	@Override
	protected Class<?> getBeanClass(Element element) {
		return User.class;
	}

	@Override
	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		// 获取属性
		String name = element.getAttribute("name");
		int age = Integer.parseInt(element.getAttribute("age"));
		String addr = element.getAttribute("addr");
		String gender = element.getAttribute("gender");

		// 给bean赋值
		builder.addPropertyValue("name", name);
		builder.addPropertyValue("age", age);
		builder.addPropertyValue("addr", addr);
		builder.addPropertyValue("gender", gender);
	}
}
